<?php 

$id = htmlentities(mysql_real_escape_string($_GET['id']));

$kegiatan = getKegiatanbyID($id);

if ($kegiatan) {

	$o .= '<form class="form-horizontal" id="registerHere" method="post" action="?page=editkegiatan&action=edit">
  			<fieldset>
			<legend>EDIT KEGIATAN</legend>';
		
	$o = "";
	  
	   /* alert yang muncul setelah proses */
	   if (isset($_GET['success']) && ($_GET['success'] == "1")) {

			$o .= '<div class="alert alert-success">
					Proses edit kegiatan berhasil
					</div>';
					
		} elseif (isset($_GET['success']) && ($_GET['success'] == "0")) {
			
			$o .= '<div class="alert alert-error">
					Proses edit kegiatan gagal
				   </div>';
		}
		
		foreach ($kegiatan as $x) {
	
			$o .= '	
				<div class="control-group">
				  <label class="control-label" for="input01">Nama Kegiatan</label>
				  <div class="controls">
					<input type="text" class="input-xlarge" id="kegiatan" value="'.$x['nama_kegiatan'].'" name="kegiatan" rel="popover" data-content="Masukkan nama kegiatan." data-original-title="Kegiatan">
				  </div>
				</div>
				
				<div class="control-group">
				  <label class="control-label" for="input01">Kabupaten</label>
				  <div class="controls">
					<select name="kabupaten" id="kabupaten" class="chzn-select" style="width:280px;" tabindex="2">';
					
					
					/* memanggil fungsi untuk menampilkan data kabupaten */
					$kabupaten	= getKab(); 

					$o2 .= '<option value='.$x['idkabkota'].'>'.$x['kabupaten'].'</option>';
					
					if ($kabupaten) {
						foreach ($kabupaten as $y) {
							$o2 .= '<option value='.$y['idkabkota'].'>'.$y['nama_kabkota'].'</option>';
						}
					} else {
						$o2 .= '<option value="">tidak ada data kabupaten</option>';
					}
					
					
					
			$o .= '		
					</select>
					</div>
				</div>
	
			<div class="control-group">
			  <label class="control-label" for="input02">Sektoral</label>
			  <div class="controls">
				<select name="sektoral" id="sektoral" class="chzn-select" style="width:280px;" tabindex="2">';
		
		
		/* memanggil fungsi untuk menampilkan data sektoral */
		$sektoral	= getSektoral();

		/* menampilkan data sektoral */
		$o3 .= '<option value='.$x['idsektoral'].'>'.$x['sektoral'].'</option>';
		foreach ($sektoral as $y) {
			$o3 .= '<option value='.$y['idsektoral'].'>'.$y['nama_sektoral'].'</option>';
		}

	
		$o .= '
				</select>
				</div>
			</div>

			<div class="control-group">
				<label class="control-label" for="input01">Pagu</label>
				  <div class="controls">
					<input type="text" class="input-xlarge" id="pagu" value="'.$x['pagu'].'" name="pagu" rel="popover" data-content="Masukkan pagu" data-original-title="Pagu">
				  </div>
			</div>
			
			<div class="control-group">
				<label class="control-label" for="input01">Longitude</label>
				  <div class="controls">
					<input type="text" class="input-xlarge" id="longitude" value="'.$x['long'].'" name="longitude" rel="popover" data-content="Masukkan longitude" data-original-title="Longitude">
				  </div>
			</div>
			
			<div class="control-group">
				<label class="control-label" for="input01">Latitude</label>
				  <div class="controls">
					<input type="text" class="input-xlarge" id="latitude" value="'.$x['lat'].'" name="latitude" rel="popover" data-content="Masukkan Latitude" data-original-title="Latitude">
				  </div>
			</div>

			<div class="control-group">
				<label class="control-label" for="input01"></label>
				  <div class="controls">
				   <button type="submit" class="btn btn-success" rel="tooltip">Edit Kegiatan</button>
				  </div>
			</div>
			  </fieldset>
			</form>';
		}
} else {
	$o .= '<div class="alert alert-error">
			Data tidak ditemukan
		    </div>';
	
}

	echo $o;
	echo $o2;
	echo $o3;
?>
		
		<a href="?page=kegiatan">kembali</a>

<?php


if ($_GET['action'] == "add") {
	
	$nama_kegiatan	= htmlentities(mysql_real_escape_string($_POST['kegiatan']));
	$kabkota		= htmlentities(mysql_real_escape_string($_POST['kabupaten']));
	$sektor			= htmlentities(mysql_real_escape_string($_POST['sektoral']));
	$pagu			= htmlentities(mysql_real_escape_string($_POST['pagu']));
	$longitude		= htmlentities(mysql_real_escape_string($_POST['longitude']));
	$latitude		= htmlentities(mysql_real_escape_string($_POST['latitude']));
	$tahun			= date('Y');
	$username		= $_SESSION['username'];
	
	$o = "";
	
	$kegiatan = addKegiatan($nama_kegiatan, $sektor, $kabkota, $pagu, $longitude, $latitude, $tahun, $username);
	
	if ($kegiatan) {
		?>
		<script language="javascript">
		document.location="?page=addkegiatan&success=1";
		</script>
		<?php
	} else {
		?>
			<script language="javascript">
			document.location="?page=addkegiatan&success=0";
			</script>
		<?php
	}
	
}





